﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Cosmetic.Logic;

namespace WebApp.Management.CPS
{
    public partial class CPSQuery : PageBase2
    {
        private RoleManager m_RoleManager = new RoleManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.SignInUser1 == null)
            {
                Session.Remove("SignInUser1");
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('请先登录权限!');window.top.location.href='/Management/indexs.aspx';", true);
                return;
            }
            if (!IsPostBack)
            {
                Cosmetic.DataEntity.User theUser = this.SignInUser1;
                if (!this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Admin))
                {
                    Session.Remove("SignInUser1");
                    this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('你没有管理员权限!');window.top.location.href='/Management/indexs.aspx';", true);
                    return;
                }
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("temple_id");
            dt.Columns.Add("temple_name");
            dt.Columns.Add("location");
            dt.Columns.Add("build_date");

            if (dt.Rows.Count == 0)
            {
                dt.Rows.Add(dt.NewRow());
            }

            this.GridViewEmptyDataTest.DataSource = dt;
            this.GridViewEmptyDataTest.DataBind();

            int columnCount = dt.Columns.Count;
            GridViewEmptyDataTest.Rows[0].Cells.Clear();
            GridViewEmptyDataTest.Rows[0].Cells.Add(new TableCell());
            GridViewEmptyDataTest.Rows[0].Cells[0].ColumnSpan = columnCount;
            GridViewEmptyDataTest.Rows[0].Cells[0].Text = "没有记录";
            GridViewEmptyDataTest.Rows[0].Cells[0].Style.Add("text-align", "center");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}